#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>

int main()
{
    int fd1 = open("log1.txt", O_CREAT | O_TRUNC | O_WRONLY, 0666);
    if(fd1 < 0) exit(1);

    close(1);
    dup2(fd1, 1);

    printf("fd->%d\n", fd1); 
    printf("hello bit\n");
    fprintf(stdout, "hello world\n");
    








    
    
    //printf("stdin->%d\n", stdin->_fileno);
    //printf("stdout->%d\n", stdout->_fileno);
    //printf("stderr->%d\n", stderr->_fileno);

    //printf("\n");

    //int fd1 = open("log1.txt", O_CREAT | O_TRUNC | O_WRONLY, 0666);
    //int fd2 = open("log2.txt", O_CREAT | O_TRUNC | O_WRONLY, 0666);
    //int fd3 = open("log3.txt", O_CREAT | O_TRUNC | O_WRONLY, 0666);
    //int fd4 = open("log4.txt", O_CREAT | O_TRUNC | O_WRONLY, 0666);
    //if(fd1 < 0) return 1;
    //if(fd2 < 0) return 1;
    //if(fd3 < 0) return 1;
    //if(fd4 < 0) return 1;

    //printf("fd1->%d\n", fd1); 
    //printf("fd2->%d\n", fd2);
    //printf("fd3->%d\n", fd3);
    //printf("fd4->%d\n", fd4);

    //close(fd1);
    //close(fd2);
    //close(fd3);
    //close(fd4);

    //return 0;
}
